﻿#region copyright
//<copyright>
// Copyright(C) 2012 TrackerRealm Corporation
// This file is part of the open source project - Jazz. http://jazz.codeplex.com
// 
// Jazz is open software: you can redistribute it and/or modify it 
// under the terms of the GNU Affero General Public License (AGPL) as published by 
// the Free Software Foundation, version 3 of the License.
// 
// Jazz is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty 
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
//  See the GNU Affero General Public License (AGPL) for more details.
// 
// You should have received a copy of the GNU General Public 
// License along with Jazz.  If not, see <http://www.gnu.org/licenses/>.
//
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT. 
//</copyright>
#endregion
#region using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using TrackerRealm.Jazz.Common;
using C = TrackerRealm.Jazz.Common.JazzConstants;
#endregion


namespace TrackerRealm.Jazz.Client.Custom
{
    /// <summary>
    /// A Jazz Role class represents a role.
    /// <para>The role class allows roles to be strongly typed. </para> 
    /// </summary>
    [Root]
    [Jazz]
    [UseEmptyObjectFor(typeof(jRoleBase))]
    public class jRole:jRoleBase
    {

        #region EmptyID
        /// <summary>
        /// The ID for the 'empty' role.
        /// </summary>
        public static readonly Guid EmptyID = new Guid("90DFB524-4DCD-4879-B877-13AE0DAA33CB");
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public new static jRole[] EmptyArray = new jRole[0];
        //
        // Factory Methods
        //
        #region CreateEmpty
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static jRole CreateEmpty()
        {
            return jRole.Create(C.EMPTY);
        }
        #endregion
        #region Create a Role (string roleName)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public static jRole Create(string roleName)
        {
            return new jRole(roleName);
        }
        #endregion
        #region Create a Role (ClientNexus nexus, string roleName)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="nexus"></param>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public static jRole Create(ClientNexusBase nexus, string roleName)
        {
            return new jRole(nexus, roleName);
        }
        #endregion
        //
        // Constructors
        //
        #region Constructor jRole(string name)
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name"></param>
        protected jRole(string name)
        :base(name)
        {
        }
        #endregion
        #region Constructor jRole(ClientNexusBase nexus, string name)
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="nexus"></param>
        /// <param name="name"></param>
        protected jRole(ClientNexusBase nexus, string name)
            : base(nexus, name)
        {
        }
        #endregion
        //
        // Instance Methods and Properties
        //
        #region Roles
        /// <summary>
        /// 
        /// </summary>
        public IEnumerable<jRole> Roles
        {
            get { return base._Roles.Cast<jRole>(); }
        }
        #endregion
        #region Add/Remove role
        /// <summary>
        /// Add a role to this role.
        /// </summary>
        /// <param name="role"></param>
        public void AddRole(jRole role)
        {
            base._AddRole(role);
        }
        /// <summary>
        /// Remove a role.
        /// <para>Removing a role from itself has the effect of disabling that role for all users that have that role.</para>
        /// </summary>
        /// <param name="role"></param>
        public void RemoveRole(jRole role)
        {
            base._RemoveRole(role);
        }
        #endregion
        #region IsRoleValid
        ///// <summary>
        ///// *** Not Implemented ***
        ///// Return true when this role is valid.
        ///// <para>This feature allows roles to have their rights revoked or
        ///// to have features such as being valid up till a certain period of time</para>
        ///// </summary>
        //public override bool IsRoleValid
        //{
        //    get { return true; }
        //}
        #endregion

        #region ACL -Add/Remove
        /// <summary>
        /// The ACL (Access Control List) controls how this '<see cref="jObject"/>' instance
        /// can be accessed.
        /// <para>Note: If the ACL sequence is empty then there are no access restrictions.</para>
        /// </summary>
        public IEnumerable<jAclItem> ACL
        {
            get { return base._ACL; }
        }
        /// <summary>
        /// Add a '<see cref="jAclItem"/>' to this jObject's ACL.
        /// </summary>
        /// <param name="item"></param>
        public void Add(jAclItem item)
        {
            base._Add(item);
        }
        /// <summary>
        /// Remove a '<see cref="jAclItem"/>' from this jObject's ACL.
        /// </summary>
        /// <param name="item"></param>
        public void Remove(jAclItem item)
        {
            base._Remove(item);
        }
        #endregion
        #region Assign Fixed Ids.
        /// <summary>
        /// Assigns a fixed ID to the empty Role instance.
        /// </summary>
        /// <returns></returns>
        protected internal override Guid OnAssignID()
        {
            if (this.IsEmpty)
                return jRole.EmptyID;
            else
                return base.OnAssignID();
        }
        #endregion
    }
}
